<template>
    <div id="batch_setting" style="max-width:500px;">
        <div id="btns_list" class="btns_list" style="margin-top:20px;">
            <el-row>
                <el-col :span="24">
                    <el-button @click="btn_actions('关机')" type="success" plain>关机</el-button>
                    <el-button @click="btn_actions('开机')" type="success" plain>开机</el-button>
                    <el-button @click="btn_actions('设定温度')" type="success" plain>设定温度</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="6">
                    <el-button @click="btn_actions('模式制冷')" type="success" plain>模式制冷</el-button>
                </el-col>
                <el-col :span="6">
                    <el-button @click="btn_actions('模式制热')" type="success" plain>模式制热</el-button>
                </el-col>
                <el-col :span="6">
                    <el-button @click="btn_actions('睡眠开启')" type="success" plain>睡眠开启</el-button>
                </el-col>
                <el-col :span="6">
                    <el-button @click="btn_actions('睡眠关闭')" type="success" plain>睡眠关闭</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="6">
                    <el-button @click="btn_actions('编程开启')" type="success" plain>编程开启</el-button>
                </el-col>
                <el-col :span="6">
                    <el-button @click="btn_actions('编程关闭')" type="success" plain>编程关闭</el-button>
                </el-col>
                <el-col :span="6">
                    <el-button @click="btn_actions('童锁开启')" type="success" plain>童锁开启</el-button>
                </el-col>
                <el-col :span="6">
                    <el-button @click="btn_actions('童锁关闭')" type="success" plain>童锁关闭</el-button>
                </el-col>
            </el-row>
        </div>

        <!-- 定时操作。发送指令获取定时信息。然后展示在弹出框上面 -->
        <!-- 定时操作。保存的时候，逐个发送保存指令 -->

    </div>
</template>
<style>
.el-row {
    margin-bottom: 20px;
    &:last-child {
        margin-bottom: 0;
    }
}

.el-col {
    border-radius: 4px;
}

.bg-purple-dark {
    background: #99a9bf;
}

.bg-purple {
    background: #d3dce6;
}

.bg-purple-light {
    background: #e5e9f2;
}

.grid-content {
    border-radius: 4px;
    min-height: 36px;
}

.row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
}
</style>
<script type="text/javascript">
import VueCommon from '../VueCommon.js'
export default {
    // 数据
    data() {
        return {}
    },
    props: { //表示本组件需要哪些数据。
        device_ids: {
            type: String,
            default: '',
        }
    },
    computed: {},
    methods: {
        greet(kName) {
            alert(kName)
        },
        operate_device(ids, k, v) {
            let vm = this
            vm.ajaxPost('/api/operate_device', {
                device_ids: ids,
                operation_code: k,
                operation_value: v
            }, function(response) {
                if (response.status == 200) {
                    if (response.data.code == 1) {
                        vm.msgboxEx('操作成功', 'success')
                        vm.reload_data()
                    } else {
                        vm.msgboxEx('操作失败', 'error')
                    }
                }
            }, function(error) {
                console.log(error);
            })
        },
        btn_actions(kName) {
            let vm = this
            //操作设备
            if (kName == '关机') {
                vm.confirm('确定关闭所有设备?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    vm.operate_device(vm.device_ids, "关机", "")
                }).catch(() => {});
            } else if (kName == '开机') {
                vm.confirm('确定开启所有设备?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    vm.operate_device(vm.device_ids, "开机", "")
                }).catch(() => {});
            }else if(kName == '设定温度'){
                let setting_temperature = 25
                vm.$prompt('请输入设定温度', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /[\d]+?/,
                    inputErrorMessage: '温度格式不正确',
                    inputValue: setting_temperature,
                    inputType: "number"
                }).then(({ value }) => {
                    vm.operate_device(vm.device_ids, "设定温度", value)
                })
            }else if (kName == '模式制冷') {
                 vm.confirm('确定将所有设备模式设置为制冷?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "模式制冷", "")
                    }).catch(() => {

                    });
            }else if (kName == '模式制热') {
                 vm.confirm('确定将所有设备模式设置为制热?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "模式制热", "")
                    }).catch(() => {

                    });
            }else if (kName == '睡眠开启') {
                 vm.confirm('确定将所有设备睡眠开启?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "睡眠开启", "")
                    }).catch(() => {

                    });
            }else if (kName == '睡眠关闭') {
                 vm.confirm('确定将所有设备睡眠关闭?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "睡眠关闭", "")
                    }).catch(() => {

                    });
            }else if (kName == '编程开启') {
                 vm.confirm('确定将所有设备编程开启?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "编程开启", "")
                    }).catch(() => {

                    });
            }else if (kName == '编程关闭') {
                 vm.confirm('确定将所有设备编程关闭?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "编程关闭", "")
                    }).catch(() => {

                    });
            } else if (kName == '童锁开启') {
                 vm.confirm('确定将所有设备童锁开启?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "童锁开启", "")
                    }).catch(() => {

                    });
            } else if (kName == '童锁关闭') {
                 vm.confirm('确定将所有设备童锁关闭?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        vm.operate_device(vm.device_ids, "童锁关闭", "")
                    }).catch(() => {

                    });
            }

        }
    },
    watch: {},
    // 资源
    directives: {},
    filters: {},
    // 生命周期钩子
    beforeCreate() {},
    created() {},
    beforeMount() {},
    mounted() {

    },
    beforeUpdate() {},
    updated() {},
    activated() {},
    deactivated() {},
    beforeDestory() {},
    destoryed() {}
}
</script>
